import {Pipe, PipeTransform} from '@angular/core';

@Pipe({
  name: 'leftDay'
})
export class LeftDayPipe implements PipeTransform {
  //到处剩余天数，参数为结束日期
  transform(value: string, end?: any): any {
    let endDate = new Date(value);
    //获取截止日期的24:00时间的秒数和当前时间的秒数
    let endTime = new Date(endDate.getFullYear() + '-' + (endDate.getMonth() + 1) + '-' + (endDate.getDate() + 1)).getTime();
    let curTime = new Date().getTime();

    //获取剩余天数；结束日期减去当前日期，保存整数
    let leftDays = parseInt(((endTime - curTime) / 1000 / 60 / 60 / 24).toFixed(0));
    if (leftDays >= 0) return leftDays;
    else return null;
  }

}
